﻿var flag = "";
//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {
        //alert("postid:" + getPar1("PostID"))
        flag = getPar1("flag");
        var CategoryID = getPar1("CategoryID");
        var CategoryName = getPar1("CategoryName");
        if (flag == "Add") {
            $("#ParentID").val(CategoryID)
            $("#ParentName").val(CategoryName);
            GetParentCategory(CategoryID);
        }
        else if (flag == "Edit") {
            $("#Category").val(CategoryName);
            GetCategory(CategoryID);
        }
    });
}

//获取上级分类信息
function GetParentCategory(ParentID) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=hrCoreEmpDataBase&condition=ID='" + ParentID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].SeqNo;
            if (typeof (t) != "undefined") {
                if (flag == "Add") {
                    //$("#SeqNo").val(t + "-");
                    GetChildNextSeq(ParentID);
                }
                else if (flag == "Edit") {
                    $("#ParentName").val(list.rows[o].Category);
                }
            }
        }
    });
}

//自动生成下级分类编码
function GetChildNextSeq(ParentID) {
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/workTimeAjax.aspx?flag=getchildcategorynextseq" + "&ParentID=" + ParentID, {
        success: function (res) {
            try {
                var str = res.responseText;
                $("#SeqNo").val(str);
            }
            catch (e) {
                alert("生成编码失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}

//获取自己信息
function GetCategory(ID) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=hrCoreEmpDataBase&condition=ID='" + ID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].SeqNo;
            if (typeof (t) != "undefined") {
                $("#SeqNo").val(t);
                $("#Remark").val(list.rows[o].Remark);
                $("#ParentID").val(list.rows[o].ParentID);
                GetParentCategory(list.rows[o].ParentID);
            }
        }
    });
}

var fnCheckData = function () {
    try {
        if ($("#ClassName").val() == "") {
            return "【分类名称】不能为空!";
        }
        if ($("#ParentID").val() == "") {
            return "【上级分类】不能为空!";
        }
        if ($("#SeqNo").val() == "") {
            return "【排序】不能为空!";
        }
    }
    catch (e)
     { }
}
